package com.demo0307.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/demo0307/demo04.do")
public class Demo04Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取 Session
        HttpSession session = request.getSession();
        System.out.println("sessionId = " + session.getId());
        System.out.println("session 是否为新创建?" + session.isNew());
        //设置 Session 寿命 5 秒,优先级比 配置文件高
        session.setMaxInactiveInterval(5);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
